﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using GtsServer.Common;
using System.Data.SqlClient;

namespace GtsServer.DAL
{
    public class FeedBackDAL
    {
        public DataSet Add(string userAccount, string contactWay, string text)
        {
            IDataParameter[] parms = new IDataParameter[]{ 
                new SqlParameter("@userAccount",userAccount),
                new SqlParameter("@contactWay",contactWay),
                new SqlParameter("@FeedBackContent",text)
            };
            DataSet ds = DbHelperSQL.RunProcedure("InsertFeedBack", parms, "InsertFeedBack");
            return ds;
        }

        public DataSet GetList(string strWhere, int pageIndex, int pageSize)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from( select u.IMSI,u.IMEI,u.Mac,u.UserAccount,ui.Name UserName,f.RequestTime RequestTime ,f.ContactWay,f.FeedBackContent,ROW_NUMBER() OVER(order by RequestTime desc) as RowNumber ");
            strSql.Append("from dbo.FeedBack f left join [User] u on f.UserID = u.ID left join UserInfo ui on u.UserInfoID = ui.ID where 1=1 ");
            if (!string.IsNullOrEmpty(strWhere))
                strSql.Append(strWhere);
            strSql.Append(" ) a where  RowNumber BETWEEN " + ((pageIndex - 1) * pageSize + 1) + " and " + pageIndex * pageSize + ";select count(1) from FeedBack");

            return DbHelperSQL.Query(strSql.ToString());
        }
    }
}
